<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="mydiv" style="height: 100px;width: 100px;background-color: brown;" onmousedown="mouseDown()"
    onmouseup="mouseUp()"></div>

  <script>
    let mouseDownTime = 0;
    function mouseDown() {
      mouseDownTime = Date.now();
    }
    function mouseUp(params) {

      document.querySelector("#mydiv").innerHTML = `<p>鼠标按下 ${Date.now() - mouseDownTime} 毫秒</p>`;
    }
  </script>
</body>

</html>